from lgb_model import LgbModel
from embedding import Embedding
from deepfm_deepctr import DeepFmModel


def run_lgb_model(used_features, cat_feats, train_set, eval_set):
    gb_model = LgbModel(feature_names=used_features, category_features=cat_feats)
    gb_model.fit_(train_set[used_features], train_set['label'], eval_set[used_features], eval_set['label'])

    import operator
    feat_importance = list(zip(used_features, gb_model.get_feat_importance))
    feat_importance.sort(key=operator.itemgetter(1), reverse=True)
    print(feat_importance)


def run_deepctr_model(used_features, cat_feats, dense_features, train_features, train_set, eval_set):
    feat_embed = Embedding(used_features, cat_feats, dense_features)
    linear_feature_columns, dnn_feature_columns = feat_embed.embed_fit(train_features)

    train_model_input = feat_embed.embed_transform(train_set)
    eval_model_input = feat_embed.embed_transform(eval_set)

    deepfm_model = DeepFmModel(linear_feature_columns=linear_feature_columns, dnn_feature_columns=dnn_feature_columns,
                               feature_names=used_features, cat_feats=cat_feats)
    deepfm_model.model_fit(train_x_model_input=train_model_input, train_y=train_set['label'], initial_epoch=0)
